﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityAndDomainLibrary.DomainModel;
using EntityAndDomainLibrary.EntityModel;

namespace MeterService.Helpers
{
    public static class Mapper
    {
        static DataBaseAccess dbacess = new DataBaseAccess();

        public static TOUData MapEM_TOUDataToTOUData(EM_TOUData meterdata, FileArchive archive)
        {
            TOUData data = new TOUData();
            data.date_time = Convert.ToDateTime(meterdata.Timestamp);


            data.meterpointid = dbacess.GetMeterPtByName(meterdata.Metername).meterpointid;
            data.qtytypeid = dbacess.GetDatatypeByName(meterdata.Variable.ToUpper()).qtytypeid;

            data.value = Convert.ToDouble(meterdata.Value);
            data.statusid = meterdata.Status;

            data.filearchiveid = archive.filearchieveid;
            return data;

        }

        public static IList<Output> ConvertDomainMeterDataToOuputData(IList<EM_TOUData> listdata)
        {
           
                IList<Output> _listrptdata = new List<Output>();

                foreach (EM_TOUData tempdata in listdata)
                {
                    Output data = new Output();
                    data.Name = "\"" + tempdata.Timestamp + "\"";

                    data.Metername = "\"" + tempdata.Metername + "_" + tempdata.Unit + "\"";
                    data.Value = "\"" + tempdata.Value.ToString() + "\"";

                    data.Constant = "\"" + "100" + "\"";
                    _listrptdata.Add(data);
                }

                return _listrptdata;
            

            
        }
    }
}
